home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Task switcher init *)
- (* *)
- (* Copyright 1988, 1989, 1990, 1991 by H. Roy Engehausen. All rights *)
- (* reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$UNDEF taskdebug}
- {$UNDEF taskalbug}
-
- (*===========================================================================*)
- (* Initialize switcher *)
- (*===========================================================================*)
-
- PROCEDURE task_init;
-
- VAR
- array_size : LONGINT;
- i : WORD;
- stack_place : POINTER;
- stack_size : WORD;
-
-
- FUNCTION build_a_tcb(stack_size : WORD; task_no : BYTE) : tcb_ptr;
-
- VAR
- new_tcb : tcb_ptr;
-
- BEGIN;
-
- NEW(new_tcb);
- FILLCHAR(new_tcb^, SIZEOF(tcb), #0);
-
- WITH new_tcb^ DO
- BEGIN;
-
- tcb_dead := TRUE;
- tcb_number := task_no;
-
- GETMEM(stack_place, stack_size);
- FILLCHAR(stack_place^, stack_size, 0);
- sseg_init := SEG(stack_place^);
- sptr_init := stack_size + OFS(stack_place^) - 16;
-
- {$IFDEF taskdebug}
- WRITELN;
- WRITELN('TASKNO = ',task_no);
- WRITELN('STACK = ',p2x(stack_place));
- WRITELN('HEAPPTR = ',p2x(HEAPPTR));
- WRITELN('SPTR = ', sptr_init);
- WRITELN;
- DELAY(3000);
- {$ENDIF};
-
- END;
-
- build_a_tcb := new_tcb
-
- END;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Show we are in system startup *)
- (*-----------------------------------------------------------------------*)
-
- system_startup := TRUE;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize some things *)
- (*-----------------------------------------------------------------------*)
-
- dead_tcb_list := NIL;
-
- (*-----------------------------------------------------------------------*)
- (* Allocate the array of TCBS *)
- (*-----------------------------------------------------------------------*)
-
- array_size := (LONGINT(opt_block.max_task_no) + 1)
- * SIZEOF(task_array_element);
-
- GETMEM(task_array_ptr, array_size);
-
- (*-----------------------------------------------------------------------*)
- (* Now allocate the TCBs *)
- (*-----------------------------------------------------------------------*)
-
- FOR i := 1 TO opt_block.max_task_no DO
- BEGIN;
- task_array_ptr^[i].element_stack_size := user_stack_size;
- task_array_ptr^[i].element_tcb_ptr :=
- build_a_tcb(user_stack_size, i + 19);
- END;
-
- {$IFDEF taskdebug}
- WRITELN;
- WRITELN('HEAPORG = ',p2x(HEAPORG));
- WRITELN('HEAPPTR = ',p2x(HEAPPTR));
- WRITELN('FREEPTR = ',p2x(FREEPTR));
- WRITELN('STACK = ',pw2x(SSEG, SPTR));
- WRITELN('DSEG = ',w2x(DSEG));
- WRITELN('PREFIX = ',w2x(PREFIXSEG));
- WRITELN;
- DELAY(3000);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Now allocate the forward sub_task *)
- (*-----------------------------------------------------------------------*)
-
- INC(opt_block.max_task_no);
- i := opt_block.max_task_no;
- task_array_ptr^[i].element_stack_size := forwardsub_stack_size;
- task_array_ptr^[i].element_tcb_ptr :=
- build_a_tcb(forwardsub_stack_size, i + 19);
-
- {$IFDEF taskalbug}
- WRITELN('FWDTASK init = ', i, ' / ', forwardsub_stack_size);
- DELAY(1000);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Exit with task 1 running but use the dummy port *)
- (*-----------------------------------------------------------------------*)
-
- NEW(active_tcb);
- FILLCHAR(active_tcb^, SIZEOF(tcb), 0);
-
- active_tcb^.tcb_number := 1;
-
- active_port := @dummy_port;
-
- tcb_init(active_tcb);
-
- active_tcb^.next_tcb := active_tcb;
-
- ring_tcb := active_tcb;
-
- alive_tcb_count := 1;
-
- main_tcb := active_tcb;
-
- main_tcb^.tcb_type := th_main;
-
- {$IFDEF taskdebug}
- WRITELN;
- WRITELN('Exit taski');
- WRITELN;
- DELAY(3000);
- {$ENDIF}
-
- END;